<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates a new DOMElement object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.domelement.html">« DOMElement</a></li>
      <li style="float: right;"><a href="domelement.getattribute.html">DOMElement::getAttribute »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.domelement.html">DOMElement</a></li>
    <li>Creates a new DOMElement object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="domelement.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMElement::__construct</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DOMElement::__construct</span> &mdash; <span class="dc-title">
   Creates a new DOMElement object
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domelement.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DOMElement::__construct</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$qualifiedName</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$value</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$namespace</code><span class="initializer"> = &quot;&quot;</span></span>)</div>
 
  <p class="para rdfs-comment">
   Creates a new <span class="classname"><a href="class.domelement.html" class="classname">DOMElement</a></span> object. This object is read only. 
   It may be appended to a document, but additional nodes may not be appended to this node until 
   the node is associated with a document. To create a writeable node, use 
   <a href="domdocument.createelement.html" class="xref">DOMDocument::createElement</a> or 
   <a href="domdocument.createelementns.html" class="xref">DOMDocument::createElementNS</a>.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-domelement.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">qualifiedName</code></dt>

     <dd>

      <p class="para">
       The tag name of the element. When also passing in namespaceURI, the element name 
       may take a prefix to be associated with the URI.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       The value of the element.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">namespace</code></dt>

     <dd>

      <p class="para">
       A namespace URI to create the element within a specific namespace.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-domelement.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5414">
    <p><strong>示例 #1 Creating a new DOMElement</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$dom&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">(</span><span style="color: #DD0000">'1.0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'iso-8859-1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$element&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">appendChild</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">DOMElement</span><span style="color: #007700">(</span><span style="color: #DD0000">'root'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$element_ns&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMElement</span><span style="color: #007700">(</span><span style="color: #DD0000">'pr:node1'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'thisvalue'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'http://xyz'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$element</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">appendChild</span><span style="color: #007700">(</span><span style="color: #0000BB">$element_ns</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();&nbsp;</span><span style="color: #FF8000">/*&nbsp;&lt;?xml&nbsp;version="1.0"&nbsp;encoding="utf-8"?&gt;<br />&lt;root&gt;&lt;pr:node1&nbsp;xmlns:pr="http://xyz"&gt;thisvalue&lt;/pr:node1&gt;&lt;/root&gt;&nbsp;*/<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-domelement.construct-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="domdocument.createelement.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::createElement()</a> - Create new element node</span></li>
    <li class="member"><span class="methodname"><a href="domdocument.createelementns.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::createElementNS()</a> - Create new element node with an associated namespace</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>